package com.handinfo.android.core.geom;

import java.io.Serializable;

public abstract class DWPoint2D
{
	public abstract double getX();

	public abstract double getY();

	/**
	 * 设置坐标
	 * @param x
	 * @param y
	 */
	public abstract void setLocation(double x, double y);

	/**
	 * 根据点P设置坐标
	 * @param p
	 */
	public void setLocation(DWPoint2D p)
	{
		setLocation(p.getX(), p.getY());
	}

	/**
	 * 点p1(x1,y1) 与 点p2(x2,y2) 间距离的平方
	 * @param x1
	 * @param y1
	 * @param x2
	 * @param y2
	 * @return
	 */
	public static double distanceSquare(double x1, double y1, double x2, double y2)
	{
		double distanceX = x1 - x2;
		double distanceY = y1 - y2;
		return distanceX * distanceX + distanceY * distanceY;
	}

	/**
	 * 点p1 与 点p2 间距离的平方
	 * @param p1
	 * @param p2
	 * @return
	 */
	public static double distanceSquare(DWPoint2D p1, DWPoint2D p2)
	{
		double distanceX = p1.getX() - p2.getX();
		double distanceY = p1.getY() - p2.getY();
		return distanceX * distanceX + distanceY * distanceY;
	}

	/**
	 * 点p1(x1,y1) 与 点p2(x2,y2) 间距离
	 * @param x1
	 * @param y1
	 * @param x2
	 * @param y2
	 * @return
	 */
	public static double distanceSqrt(double x1, double y1, double x2, double y2)
	{
		double distanceX = x1 - x2;
		double distanceY = y1 - y2;
		return Math.sqrt(distanceX * distanceX + distanceY * distanceY);
	}

	/**
	 * 点p1 与 点p2 间距离
	 * @param p1
	 * @param p2
	 * @return
	 */
	public static double distanceSqrt(DWPoint2D p1, DWPoint2D p2)
	{
		double distanceX = p1.getX() - p2.getX();
		double distanceY = p1.getY() - p2.getY();
		return Math.sqrt(distanceX * distanceX + distanceY * distanceY);
	}

	/**
	 * 与 点p(x1,y1) 间距离
	 * @param x1
	 * @param y1
	 * @return
	 */
	public double distanceSqrt(double x1, double y1)
	{
		double distanceX = getX() - x1;
		double distanceY = getY() - y1;
		return Math.sqrt(distanceX * distanceX + distanceY * distanceY);
	}

	/**
	 * 与点P间的距离
	 * @param p
	 * @return
	 */
	public double distanceSquare(DWPoint2D p)
	{
		double distanceX = getX() - p.getX();
		double distanceY = getY() - p.getY();
		return distanceX * distanceX + distanceY * distanceY;
	}

	public static class Float extends DWPoint2D implements Serializable
	{
		/**
		 * 
		 */
		private static final long serialVersionUID = 3253909890808112342L;

		/** 坐标 */
		private float m_x, m_y;

		public Float()
		{
			super();
		}

		public Float(float x, float y)
		{
			super();
			m_x = x;
			m_y = y;
		}

		@Override
		public double getX()
		{
			return m_x;
		}

		@Override
		public double getY()
		{
			return m_y;
		}

		@Override
		public void setLocation(double x, double y)
		{
			m_x = (float) x;
			m_y = (float) y;
		}

	}

	public static class Double extends DWPoint2D implements Serializable
	{
		/**
		 * 
		 */
		private static final long serialVersionUID = 2521977909051781358L;

		/** 坐标 */
		private double m_x, m_y;

		public Double()
		{
			super();
		}

		public Double(double x, double y)
		{
			super();
			m_x = x;
			m_y = y;
		}

		@Override
		public double getX()
		{
			return m_x;
		}

		@Override
		public double getY()
		{
			return m_y;
		}

		@Override
		public void setLocation(double x, double y)
		{
			m_x = x;
			m_y = y;
		}

	}
}
